"""工作流配置管理"""

WORKFLOW_CONFIGS = {
    "hotspot_analysis": {
        "description": "热点数据分析工作流",
        "agents": [
            "DataCollectionAgent",
            "SummaryGenerationAgent"
        ],
        "timeout": 300,  # 5分钟超时
        "input_schema": {
            "type": "object",
            "properties": {
                "max_events": {"type": "integer", "default": 10}
            }
        }
    },
    "content_creation": {
        "description": "内容创作工作流", 
        "agents": [
            "DataCollectionAgent",
            "SummaryGenerationAgent", 
            "CopywritingGenerationAgent"
        ],
        "timeout": 600,  # 10分钟超时
        "input_schema": {
            "type": "object",
            "required": ["hotspot_title", "platforms", "styles"],
            "properties": {
                "hotspot_title": {"type": "string"},
                "hotspot_content": {"type": "string", "default": ""},
                "platforms": {"type": "object"},
                "styles": {"type": "array"}
            }
        }
    },
    "content_publishing": {
        "description": "内容创作与发布工作流", 
        "agents": [
            "DataCollectionAgent",
            "SummaryGenerationAgent", 
            "CopywritingGenerationAgent",
            "PublishAgent"
        ],
        "timeout": 900,  # 15分钟超时
        "input_schema": {
            "type": "object",
            "required": ["hotspot_title", "platforms", "styles", "platforms_to_publish"],
            "properties": {
                "hotspot_title": {"type": "string"},
                "hotspot_content": {"type": "string", "default": ""},
                "platforms": {"type": "object"},
                "styles": {"type": "array"},
                "platforms_to_publish": {"type": "array", "default": ["weibo", "douyin", "wechat"]},
                "publish_schedule": {"type": "string", "default": "immediate"}  # immediate, scheduled
            }
        }
    },
    "trend_analysis": {
        "description": "趋势分析工作流",
        "agents": [
            "DataCollectionAgent",
            "SummaryGenerationAgent",
            "TrendAnalysisAgent"
        ],
        "timeout": 400,  # 6分钟超时
        "input_schema": {
            "type": "object",
            "properties": {
                "include_word_cloud": {"type": "boolean", "default": True},
                "include_stats": {"type": "boolean", "default": True},
                "include_trends": {"type": "boolean", "default": True}
            }
        }
    },
    "full_analysis": {
        "description": "完整分析工作流（包含趋势分析）",
        "agents": [
            "DataCollectionAgent",
            "SummaryGenerationAgent",
            "TrendAnalysisAgent"
        ],
        "timeout": 500,  # 8分钟超时
        "input_schema": {
            "type": "object",
            "properties": {
                "max_events": {"type": "integer", "default": 10}
            }
        }
    },
    "data_only": {
        "description": "仅数据收集工作流",
        "agents": ["DataCollectionAgent"],
        "timeout": 120,  # 2分钟超时
        "input_schema": {
            "type": "object",
            "properties": {}
        }
    }
}

def get_workflow_config(workflow_name: str) -> dict:
    """获取工作流配置"""
    if workflow_name not in WORKFLOW_CONFIGS:
        raise ValueError(f"工作流 '{workflow_name}' 不存在")
    return WORKFLOW_CONFIGS[workflow_name]

def get_available_workflows() -> dict:
    """获取所有可用工作流"""
    return {
        name: {
            "description": config["description"],
            "agents": config["agents"],
            "timeout": config["timeout"]
        }
        for name, config in WORKFLOW_CONFIGS.items()
    }

def validate_workflow_input(workflow_name: str, input_data: dict) -> bool:
    """验证工作流输入数据"""
    if workflow_name not in WORKFLOW_CONFIGS:
        return False
    
    schema = WORKFLOW_CONFIGS[workflow_name].get("input_schema", {})
    required_fields = schema.get("required", [])
    
    for field in required_fields:
        if field not in input_data:
            return False
    
    return True
